Page({
  data: {
    searchKeyword: '',
    zoneResults: [],
    buildingResults: [],
    companyResults: []
  },

  onLoad(options) {
    // 如果从其他页面跳转过来并带有搜索关键词，则执行搜索
    if (options.keyword) {
      this.setData({
        searchKeyword: decodeURIComponent(options.keyword)
      });
      this.performSearch();
    }
  },

  onSearchInput(e) {
    this.setData({
      searchKeyword: e.detail.value
    });
  },

  onSearch() {
    const keyword = this.data.searchKeyword;
    if (!keyword) {
      wx.showToast({
        title: '请输入搜索关键词',
        icon: 'none'
      });
      return;
    }
    
    this.performSearch();
  },

  performSearch() {
    const keyword = this.data.searchKeyword;
    
    // 模拟搜索结果
    // 在实际开发中，这里应该调用后端API进行搜索
    
    // 片区搜索结果
    const zoneResults = [
      { id: 1, name: 'A区', location: '园区东侧', address: '北京市朝阳区某某路123号', buildingCount: 10, totalArea: 50000, rentedArea: 35000, availableArea: 15000 },
      { id: 2, name: 'B区', location: '园区西侧', address: '北京市朝阳区某某路125号', buildingCount: 8, totalArea: 40000, rentedArea: 30000, availableArea: 10000 }
    ].filter(item => item.name.includes(keyword));
    
    // 楼宇搜索结果
    const buildingResults = [
      { id: 1, name: 'A1栋', image: 'https://via.placeholder.com/100x100?text=A1', location: 'A区', address: '北京市朝阳区某某路123号A1栋', totalArea: 5000, rentedArea: 3000, availableArea: 2000 },
      { id: 2, name: 'B1栋', image: 'https://via.placeholder.com/100x100?text=B1', location: 'B区', address: '北京市朝阳区某某路125号B1栋', totalArea: 8000, rentedArea: 6000, availableArea: 2000 }
    ].filter(item => item.name.includes(keyword) || item.location.includes(keyword));
    
    // 企业搜索结果
    const companyResults = [
      { id: 1, name: 'ABC科技有限公司', logo: 'https://via.placeholder.com/100x100?text=ABC', address: '北京市朝阳区某某路123号A1栋3层', joinTime: '2023-01-15', rentPeriod: '1年', expireTime: '2024-01-14' },
      { id: 2, name: 'XYZ制造有限公司', logo: 'https://via.placeholder.com/100x100?text=XYZ', address: '北京市朝阳区某某路125号B1栋2层', joinTime: '2023-03-20', rentPeriod: '1年', expireTime: '2024-03-19' }
    ].filter(item => item.name.includes(keyword));
    
    this.setData({
      zoneResults,
      buildingResults,
      companyResults
    });
  },

  onZoneTap(e) {
    const zoneId = e.currentTarget.dataset.id;
    // 跳转到片区详情页面
    wx.navigateTo({
      url: `/pages/areaOverview/areaOverview?id=${zoneId}`
    });
  },

  onBuildingTap(e) {
    const buildingId = e.currentTarget.dataset.id;
    // 跳转到楼宇详情页面
    wx.navigateTo({
      url: `/pages/buildingDetail/buildingDetail?id=${buildingId}`
    });
  },

  onCompanyTap() {
    // 可以跳转到企业详情页面（如果需要的话）
    wx.showToast({
      title: '跳转到企业详情',
      icon: 'none'
    });
  }
});